<?php
namespace app\admin\controller;
use app\common\controller\AdminController;
use app\common\model\Config as  configModel;
use think\facade\View;


class Config extends AdminController {

    public function index(){

        $model = new configModel();
        if($this->request->isPost()){
            $configdata = $this->request->post('data');
            foreach ($configdata as $k=>$v){
                $model->where('key',$k)->save(['value'=>$v]);
            }
            $this->setActionLog('编辑平台设置',$this->admin_info['name']);
            $re = [
                'status'=>true,
                'msg'=>'保存成功',
            ];
            return $re;
        }
        $config = $model->select()->toArray();
        foreach ($config as $info){
            $data[$info['key']]['name'] =  $info['desc'];
            $data[$info['key']]['value'] =  $info['value'];
        }
        View::assign('data',$data);

        return View::fetch();

    }

}
